package com.ybkj.o2o.mc.common.transport;

import com.ybkj.o2o.mc.entity.Passenger;
import com.ybkj.o2o.mc.entity.PassengerConcats;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by shine on 16/9/14.
 */
public class PassengerConcatsResult extends PassengerConcats {

  private Long id;

  private String name;  //紧急联系人姓名

  private String phone;  //紧急联系人电话

  @JsonProperty(value = "passenger_id")
  private Long passengerId;//乘客Id

  private Date created;

  private Date updated;

  @JsonProperty(value = "passenger_name")
  private String passengerName;

  @JsonProperty(value = "passenger_phone")
  private String passengerPhone;

  @Override
  public Long getId() {
    return id;
  }

  @Override
  public void setId(Long id) {
    this.id = id;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public void setName(String name) {
    this.name = name;
  }

  @Override
  public String getPhone() {
    return phone;
  }

  @Override
  public void setPhone(String phone) {
    this.phone = phone;
  }

  public Long getPassengerId() {
    return passengerId;
  }

  public void setPassengerId(Long passengerId) {
    this.passengerId = passengerId;
  }

  @Override
  public Date getCreated() {
    return created;
  }

  @Override
  public void setCreated(Date created) {
    this.created = created;
  }

  @Override
  public Date getUpdated() {
    return updated;
  }

  @Override
  public void setUpdated(Date updated) {
    this.updated = updated;
  }

  public String getPassengerName() {
    return passengerName;
  }

  public void setPassengerName(String passengerName) {
    this.passengerName = passengerName;
  }

  public String getPassengerPhone() {
    return passengerPhone;
  }

  public void setPassengerPhone(String passengerPhone) {
    this.passengerPhone = passengerPhone;
  }

  /**
   * 把PassengerConcats类型转换为PassengerConcatsResult用于输出.
   *
   * @param concatses 联系人信息
   * @return 联系人信息输出对象
   */
  public static List<PassengerConcatsResult> convertFrom(List<PassengerConcats> concatses) {

    return concatses.stream().map(concat -> convertFrom(concat)).collect(Collectors.toList());

  }

  /**
   * 把PassengerConcats类型转换为PassengerConcatsResult用于输出.
   *
   * @param concats 联系人信息
   * @return 联系人信息输出对象
   */
  public static PassengerConcatsResult convertFrom(PassengerConcats concats) {

    PassengerConcatsResult result = new PassengerConcatsResult();

    BeanUtils.copyProperties(concats, result, "passenger", "passengerName",
            "passengerPhone", "passengerId");

    result.setPassengerId(concats.getPassengerId());

    Passenger passenger = concats.getPassenger();
    if (null != passenger) {
      result.setPassengerName(passenger.getName());
      result.setPassengerPhone(passenger.getPhone());
    }

    return result;
  }

}
